/*
    Android UIML

	Copyright (C) 2010  Bram Goffings (bramgoffings@gmail.com)

	This program is free software; you can redistribute it and/or
	modify it under the terms of the GNU Lesser General Public License
	as published by the Free Software Foundation; either version 2.1
	of	the License, or (at your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU Lesser General Public License for more details.

	You should have received a copy of the GNU Lesser General Public License
	along with this program; if not, write to the Free Software
	Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
*/

package uiml.android.template;

import java.util.Hashtable;

/**
 * Singleton klasse waar alle templates worden opgeslagen
 * 
 * @author bram
 */
public class TemplateRepository {

	// TODO comment
	private static TemplateRepository instance = null;
	private Hashtable<String, Template> templates;

	/**
	 * 
	 */
	protected TemplateRepository() {	
		templates = new Hashtable<String, Template>();
	}

	/**
	 * 
	 * @return
	 */
	public static TemplateRepository getInstance() {
		if(instance==null)
			instance = new TemplateRepository();
		
		return instance;
	}

	/**
	 * 
	 * @param t
	 */
	public void register(Template t)
	{
		templates.put(t.getId(), t);
	}

	/**
	 * 
	 * @param id
	 * @return
	 */
	public Template getTemplate(String id)
	{
		if (id.startsWith("#") == false)
			return templates.get(id);
		else
			return templates.get(id.substring(1));
	}
	
}
